/*
* $Id: DBRecord.java 292 2011-03-24 21:08:17Z volok-aleksej@yandex.ru $
*
* Copyright 2008-2010 by Volokitin Alexey
* All rights reserved
*
*/
package apiary.db;

import java.io.ByteArrayInputStream;
import java.io.DataInputStream;
import java.io.IOException;

/**
 * Common interface for database records
 * @author lexus
 */
public abstract class DBRecord
{
    /**
     * Gets byte array of record
     * @return byte array
     */
    public abstract byte[] getData();
    /**
     * Sets byte array record.
     * Array will be parsed and all fields of it will be filled
     * @param data byte array
     * @return number read byte
     */
    public int setData(byte[] data){
        int readData = 0;
        try {
            ByteArrayInputStream bais = new ByteArrayInputStream(data);
            DataInputStream dis = new DataInputStream(bais);
            setData(dis);
            readData = data.length - dis.available();
        } catch (IOException ex) {}
        return readData;
    }
    /**
     * Sets byte array record.
     * Array will be parsed and all fields of it will be filled
     * @param dis data input stream
     */
    public abstract void setData(DataInputStream dis) throws IOException;
}
